package com.example.demo.LeetCode.string;

public class ReplaceSpace {
    public static String replace(String str){
        char[] charArrs  = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (char ch : charArrs) {
           if (ch==' '){
               sb.append("%20");
           }else{
               sb.append(ch);
           }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String str = "We are happy.";
        System.out.println(replace(str));
    }
}
